//
//  MainDefaulSearctVC_Tbv.m
//  ZITHER
//
//  Created by weixin on 2018/11/19.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MainDefaulSearctVC_Tbv.h"
#import "MainDefaulSearctVC.h"
#import "MainDefaultTbCell.h"
#import "STViewController.h"

@implementation MainDefaulSearctVC_Tbv

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self Starefreshing];
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}

- (void)Starefreshing{
    
    if (self.indexType == 2) {
        return;
    }
    
    MainDefaulSearctVC *vc = (MainDefaulSearctVC*)[self getViewController:[MainDefaulSearctVC class]];
    [vc loadData];
}



#pragma MARK - 数据源
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        if (self.indexType == 2) {
            return self.arrImageM.count;
        }else{
            return self.model.goodVOs.count;
        }
   
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *sectionCell = @"MainDefaultTbCell";
    MainDefaultTbCell * cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MainDefaultTbCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.stare = MainDefaultTbCellTypeSelectWatch;
    goodVOsModel *model = nil;

    if (self.indexType == 2) {

        model = self.arrImageM[indexPath.row];

    }else{

        model =self.model.goodVOs[indexPath.row];

    }

    cell.model = model;

    return cell;

}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat heightCell = 0;
    /* TODO: ================= cell 高度通过类型区分 =================*/

    heightCell = 0;

    heightCell = 210;

    return heightCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    goodVOsModel *model = nil;
    
    if (self.indexType == 2) {
        
        model = self.arrImageM[indexPath.row];
        
    }else{
        
        model =self.model.goodVOs[indexPath.row];
        
    }
    
    
    STViewController *vc = [[STViewController alloc]init];
    vc.type = STControllerTypeHiddenNavBar;
    vc.goodId = model.goodInfo.id;
    [self.getNav pushViewController:vc animated:YES];
    
//    STViewController *vc = [[STViewController alloc]init];
//
//    goodVOsModel *model = nil;
//
//    if (self.arrM != nil) {
//
//        model = self.arrM[indexPath.row];
//
//    }else{
//
//        model =self.model.goodVOs[indexPath.row];
//
//    }
//
//    vc.goodId = model.goodInfo.id;
//
//    [self.getNav pushViewController:vc animated:YES];

}

-(void)setArrImageM:(NSMutableArray *)arrImageM{
    
    _arrImageM = arrImageM;
    
    
    self.indexType = 2;

    [self reloadData];
    
}

@end
